package simple;

import redis.clients.jedis.Jedis;


public class TestJedis {
	public static void main(String[] args) throws InterruptedException {
		  //Connecting to Redis on localhost
		  Jedis jedis = new Jedis("localhost", 6379);
		  //adding a new key
		  jedis.set("key", "wf");
		  //getting the key value
		  System.out.println(jedis.get("key"));
		  
		  System.out.println(jedis.get("counter"));
		  jedis.incr("counter");
		  System.out.println(jedis.get("counter"));
		  
		  //adding a new key
		  jedis.set("cacheKey", "cached value");
		  //setting the TTL in seconds
		  jedis.expire("cacheKey", 15);
		  //Getting the remaining ttl
		  System.out.println("TTL:" + jedis.ttl("cacheKey"));
		  Thread.sleep(1000);
		  System.out.println("TTL:" + jedis.ttl("cacheKey"));
		  //Getting the cache value
		  System.out.println("Cached Value:" + jedis.get("cacheKey"));
		  //Wait for the TTL finishs
		  Thread.sleep(15000);
		  //trying to get the expired key
		  System.out.println("Expired Key:" + jedis.get("cacheKey"));
		  
		  //Adding a set as value
		  jedis.sadd("cacheKey1","Java","C#","Python");//SADD
		  //Getting all values in the set: SMEMBERS
		  System.out.println("Languages: " + jedis.smembers("cacheKey1"));
		  //Adding new values
		  jedis.sadd("cacheKey1","Java","Ruby");
		  //Getting the values... it doesn't allow duplicates
		  System.out.println("Languages: " + jedis.smembers("cacheKey1"));
	}
}